import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class TestDemo2 {
    public static void main(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();//初始的大小是几？答案是0
        list1.add("b");//当第一次存放数据元素时，顺序表被分配大小为10
        ArrayList<String> list = new ArrayList<>(13);//初始大小指定为13
    }
    public static void main5(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("a");
        list1.add("b");
        list1.add("t");
        list1.add("c");
        list1.add("w");
        list1.add("e");
        List<String> sub = list1.subList(1,3);
        System.out.println(sub);
        System.out.println(list1);
        sub.set(1,"hu");
        System.out.println(sub);
        System.out.println(list1);
        //System.out.println(list1);
        //list1.clear();
        //String ret = list1.set(2,"o");
        //boolean ret = list1.remove("b");
        //System.out.println(ret);
//        String ret = list1.remove(0);
//        System.out.println(ret);
        //System.out.println(list1.lastIndexOf("a"));
        /*list1.add(1,"hu");
        System.out.println(list1);

        ArrayList<String> list = new ArrayList<>();
        list.add("我是1");
        list.add("我是2");
        list.add("我是3");
        list1.addAll(list);
        System.out.println(list1);*/
    }
    public static void main4(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("hi");
        list1.add("bit");
        System.out.println(list1);
        System.out.println("===迭代器list相关打印===");
        ListIterator<String> it2 = list1.listIterator();
        while (it2.hasNext()){
            String ret = it2.next();
            if (ret.equals("hi")){
                it2.add("hu");
            }else {
                System.out.println(ret+" ");
            }
        }
        System.out.println(list1);
        /*System.out.println("======迭代器打印=======");
        Iterator<String> it = list1.iterator();
        while (it.hasNext()){
            System.out.println(it.next()+" ");
        }*/
    }
    public static void main3(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("hi");
        list1.add("bit");
        System.out.println(list1);
        /*System.out.println("======迭代器打印=======");
        Iterator<String> it = list1.iterator();
        while (it.hasNext()){
            String ret = it.next();
            if (ret.equals("hello")){
                it.remove();
            }else{
                System.out.println(ret+" ");
            }
        }*/
        System.out.println("===迭代器list相关打印===");
        ListIterator<String> it2 = list1.listIterator();
        while (it2.hasNext()){
            String ret = it2.next();
            if (ret.equals("hi")){
                it2.remove();
            }else{
                System.out.println(ret+" ");
            }
        }
    }
    public static void main2(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("hi");
        list1.add("bit");
        System.out.println(list1);
        System.out.println("==============================");
        for (int i = 0; i < list1.size(); i++){
            System.out.println(list1.get(i) + " ");
        }
        System.out.println("==================");
        for (String s : list1) {
            System.out.println(s+" ");
        }
        System.out.println("======迭代器打印=======");
        Iterator<String> it = list1.iterator();
        while (it.hasNext()){
            System.out.println(it.next()+" ");
        }
        System.out.println("===迭代器list相关打印===");
        ListIterator<String> it2 = list1.listIterator();
        while (it2.hasNext()){
            System.out.println(it2.next()+" ");
        }
    }
    public static void main1(String[] args) {
        List<String> list = new ArrayList<>();
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("hello");
        list1.add("hi");
        list1.add("bit");
        System.out.println(list1);
        //使用另外一个ArrayList对list2进行初始化
        ArrayList<String> list2 = new ArrayList<>(list1);
    }
}
